<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="en">
<!--<![endif]-->
<!-- BEGIN HEAD -->

<head>
    <meta charset="utf-8" />
    <title></title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1" name="viewport" />
    <meta content="" name="description" />
    <meta content="" name="author" />
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="http://tv.speechb.com/lib/superui/content/ui/global/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link href="http://tv.speechb.com/lib/superui/content/ui/global/font-awesome/css/font-awesome.css" rel="stylesheet" />
    <!-- Theme style -->
    <link rel="stylesheet" href="http://tv.speechb.com/lib/superui/content/adminlte/dist/css/AdminLTE.css">
    <link rel="stylesheet" href="http://tv.speechb.com/lib/content/adminlte/dist/css/skins/_all-skins.min.css">
    <link href="http://tv.speechb.com/lib/superui/content/min/css/supershopui.common.min.css" rel="stylesheet" />
    <link href="http://tv.speechb.com/lib/superui/content/plugins/bootstrap-table/bootstrap-table.css" rel="stylesheet" />
    <link href="http://tv.speechb.com/lib/superui/content/layx/layx.min.css" rel="stylesheet" />
    <link href="http://tv.speechb.com/lib/x-editable/css/select2-bootstrap.css" rel="stylesheet"/>
    <link href="http://tv.speechb.com/lib/select2/css/select2.min.css" rel="stylesheet"/>
    <!--全局通用框架样式 end-->


</head>
<body>
<!--
<script id="editor" type="text/plain" style="height: 150px;"/>

-->
<!-- Main content -->
    <div class="content">
        <div class="box box-info">
            <h4 class="box-header with-border" >话术标题</h4>
        </div>

        <div  class="content" style="margin-top: 10px;max-width: 640px">

            <div class="box-body" style="max-width: 640px">
                <div class="form-group">
                    <label for="name">标题</label>
                    <input type="text" class="form-control" id="title" placeholder="请输入标题名称">
                </div>
                    <div class="form-group">
                            <label>标题类型</label>
                            <select id="title1_select" name="parentid" class="form-control">
                                <option selected="selected" value="0">--请选择--</option>
                            </select>
                    </div>
            </div>
        </div>
    </div>

<button id="submitBtn" type="button" class="btn btn-primary center-block" style="margin-top:10px"> 添加标题</button>

<script src="http://tv.speechb.com/lib/superui/content/ui/global/jQuery/jquery.min.js"></script>

<!-- Bootstrap 3.3.6 -->
<script src="http://tv.speechb.com/lib/superui/content/ui/global/bootstrap/js/bootstrap.min.js"></script>
<script src="http://tv.speechb.com/lib/select2/js/select2.full.min.js"></script>
<script src="http://tv.speechb.com/lib/superui/content/min/js/supershopui.common.js"></script>
<!--富文本框-->
<script type="text/javascript" charset="utf-8" src="http://tv.speechb.com/lib/toaster/jquery.toaster.js"></script>

<script type="text/javascript">


            $(function(){
                $(".select2").select2();
                function initSelect2(id,url) {
                    $(id).select2({
                        language: "zh-CN",// 指定语言为中午，国际化才能起效
                        inputMessage: "请选择",
                        pagination:{
                            more:true
                        },
                        ajax: {
                            url: url,
                            dataType: 'json',
                            delay:250, // 延迟显示
                            data: function (params) {
                                var query = {
                                    search: params.term,
                                    page: params.page || 1,
                                    title1_id: $("#title1_select").val(),
                                    rows: 10 //每页显示多少行
                                }

                                // Query parameters will be ?search=[term]&page=[page]
                                return query;
                            },
                            // 分页
                            processResults: function (data, params) {
                                params.page = params.page | 1;
                                return {
                                    results: data.data,// 后台返回数据
                                    pagination: {
                                        more: (params.page-1)*10<data.total// 总数
                                    }
                                };
                            },
                            cache: false
                        },
                        escapeMarkup: function (markup) {
                            return markup;
                        },
                        minimumInputLength: 0,// 0长度及搜索所以
                        templateResult: function(repo){// 显示的结果集格式，需要自己写CSS
                            // 正在检索
                            if(repo.loading) return repo.text;
                            var markup = repo.text;
                            var markup = "";
                            markup +="<div class ='select2-result-repository_statistics'>"
                                +"<div class='select2-result-repository_forks'><i class = 'fa fa-bolt'></i> &nbsp;"+repo.text+"</div>"
                                +"</div>";
                            return markup;
                        },
                        templateSelection: function(repo) {
                            // 选中某一列后文本框
                            return "<div>" +repo.text || repo.id + "</div>";
                        },
                        placeholder: '请选择'
                    });
                }
                function initTitle1() {
                    initSelect2("#title1_select","/admin/speechcraft_title/title2/title1_list?id=id");
                    // $("#title1_select").html('<option value="0">_请选择_</option>').trigger("change");
                    $("#title1_select").off().on("change",function(){
                        var data = $(this).val();
                    });
                    $("#title1_select").append(new Option("--请选择标题--", 0, true, true));//第一个参数时id,第二个参数是text
                    $("#title1_select").trigger("change");
                }
                initTitle1();
                $("#submitBtn").click(function () {
                    var title1Id = $("#title1_select").val();
                    var title = $("#title").val();
                    $.ajax({
                        //请求方式
                        type : "POST",
                        //请求地址
                        url : "/admin/speechcraft_title/title2/add",
                        //数据，json字符串
                        data : {
                            "title1_id":title1Id,
                            "title":title
                        },
                        //请求成功
                        success : function(result) {
                            if(result.code==1) {
                                $("#title").val("");
                                $.toaster({ priority : "success", title : "通知", message : "发布成功" });
                            } else {
                                $.toaster({ priority : "danger", title : "通知", message : "发布失败" })
                            }
                            console.log(result);
                        },
                        error : function(e){
                            $.toaster({ priority : "danger", title : "通知", message : "发布失败" })
                        }
                    });
                });
                $("#publish_type").select2();
            });

        </script>
</body>

</html>